package com.shishi.fast.generator.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shishi.fast.common.vo.ResponseListUtils;
import com.shishi.fast.generator.domain.CompanyDO;
import com.shishi.fast.generator.mapper.CompanyMapper;
import com.shishi.fast.generator.service.CompanyService;
import com.shishi.fast.generator.vo.CompanyRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author gemim
 * @description 针对表【sys_company(系统-企业表)】的数据库操作Service实现
 * @createDate 2024-10-22 13:22:01
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, CompanyDO> implements CompanyService {

    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public ResponseListUtils<CompanyDO> list(CompanyRequest.QueryParam param) {
        if (param.getPage() > 0) {
            PageHelper.startPage(param.getPage(), param.getLimit());
        }

        List<CompanyDO> list = companyMapper.selectList(Wrappers.<CompanyDO>lambdaQuery()
                .eq(StringUtils.isNotBlank(param.getName()), CompanyDO::getName, param.getName())
        );

        PageInfo<CompanyDO> info = PageInfo.of(list);
        return new ResponseListUtils<>(info.getList(), info.getTotal());
    }
}